define(["jquery"],function($){
  var jieXiHome= function(){
    // var $header = $("#header");
    // var h = $header.height();
    // $(window).sroll(function(){
    //   var height = $(body).scrolltop();
    //   if(height>h){
    //     $header.css("position","fixed")
    //   }
    // })

    $.get("../../index.json",function(responseText,responseTatue,responseObj){
      var $activ = responseText.data
      // console.log(responseText )
			var $infos = $activ.act_info;
			// console.log($infos);
				var $banner = $("#banner");
				var $middle = $("<div id='middle'><div>");
				$banner.append($middle);
				var $wrap = $("<div id='wrap'><div>");
				$middle.append($wrap);
				var $miaos = $(".miaos");
				var $milk = $(".milk");
				var $bianLiDian  = $(".bianLiDian")
        var $miao = $(".miao");
        var $hot = $(".hot");
        var $ya = $(".ya");
        var $hengtu = $(".hengtu")


			for(var $info of $infos){
				// console.log($info)
				if($info.act_rows.length==2){
					//  console.log($info.act_rows)
					var $lbtImgs = $info.act_rows

					for(var $lbtImg of $lbtImgs){

						var $lbtUrl = $lbtImg.activity.img
						var $imgTag = $("<img/>");
						$imgTag.attr("src",$lbtUrl);
						$wrap.append($imgTag);
					}
				}
      }





        var $middle = $("#middle");
        var $wrap = $("#wrap");
        var $imgs = $("#wrap img");
        var $cloneImg = $imgs.eq(0).clone();
        $wrap.append($cloneImg);
        var $width = $imgs.eq(0).width();
        console.log($width)

        var w = $width;
        console.log(w)
        $wrap.width($imgs.length+1 * w)
        console.log($imgs.length)

        var index = 0;

        function change() {
            index++;
            if (index > $imgs.length) {
                index = 1;
                $wrap.css("left","0");
            }
        
            $wrap.animate({left: w * index * -1 + 'px'}, 500);
        }
        var timeId = setInterval(change, 1000);
			var $infos1 = $infos[1];
			$ones = $infos1.act_rows;
			for(var $one of $ones){
				$oneImg = $one.activity.img;
				$oneName= $one.activity.name;
				// console.log($oneName);
				var $liImg1 = $("<li class='qiang'></li>");
				var $img1 = $("<img>");
				$img1.attr("src",$oneImg)
				var $liP1 = $("<p></p>");
				$liP1.text($oneName);
				$milk.append($liImg1);
				$liImg1.append($img1);
				$liImg1.append( $liP1 );

			}

			var $infos2 = $infos[3];
			$twos = $infos2.act_rows;
			for($two of $twos){
				$twoImg = $two.activity.img;
				$twoName= $two.activity.name;
				var $liImg2 = $("<li class='qiang'></li>");
				var $img2 = $("<img>");
				$img2.attr("src",$twoImg)
				var $liP2 = $("<p></p>");
				$liP2.text($twoName);
				$miaos.append($liImg2);
				$liImg2.append($img2);
				$liImg2.append( $liP2 );

			}


			var $infos3 = $infos[4];
			$three = $infos3.act_rows;
			// console.log($three);
			// console.log($three[0]);
			var $three0 = $three[0];
			var $three0Name = $three0.act_rows[0].chead_detail.name;
			var $three0Img = $three0.act_rows[0].chead_detail.img;

			var $liImg03 = $("<li class='qiang'></li>");
			var $img03 = $("<img>");
			$img03.attr("src",$three0Img)
			var $liP03 = $("<p></p>");
			$liP03.text($three0Name);
			$bianLiDian.append($liImg03);
			$liImg03.append($img03);
			// $liImg03.append( $liP03 );


      // 热销
      var $three01 = $three[1];
        var $three01 =$three01.act_rows;
      for(var $three1s of $three01){
        // console.log($three1s)
        var $hotName = $three1s.cactivity_detail.name;
  			var $hotImg = $three1s.cactivity_detail.img;
        // console.log($hotImg);
        var $hotLi = $("<li></li>");
  			var $hotTag = $("<img>");
  			$hotTag.attr("src",$hotImg);
        $hot.append($hotTag)

      }




      // 牛奶酒
			var $three2 = $three[2]
			$three2s = $three2.act_rows;
      // var $three02 = $three2.act_rows[0];
      // console.log($three2s)
      for($three02 of $three2s){
        $three02Name= $three02.cicons_detail.name;
        $three02Img= $three02.cicons_detail.img;
        // console.log($three02Name)
        var $liImg04 = $("<li class='qiang'></li>");
  			var $img04 = $("<img>");
  			$img04.attr("src",$three02Img)
  			var $liP04 = $("<p></p>");
  			$liP04.text($three02Name);

  			$miao.append($liImg04);

        $liImg04.append($img04);
        $liImg04.append($liP04);
        // console.log($miao)

      }

      // 鸭
      var $three3 = $three[3]
			$three3s = $three3.act_rows;
      // var $three02 = $three2.act_rows[0];
      // console.log($three3s)
      for($three03 of $three3s){
        $yaName= $three03.activity.name;
        $yaImg= $three03.activity.img;
        // console.log($yaName);
        var $yaLi = $("<li></li>");
  			var $yaTag = $("<img>");
  			$yaTag.attr("src",$yaImg)
  			$ya.append($yaLi);
        $yaLi.append($yaTag);
      }

        // 横图
      var $infos5 = $infos[5];
			$three5s = $infos5.act_rows;
			// console.log($three5s);
      for(var $three5 of $three5s){
        // console.log($three5.category_detail.goods);
        $title = $three5.activity.name;
        $bigUrl = $three5.activity.img;
        $bigDiv = $("<div class='myDiv'></div>");
        $titleP = $("<h3></h3>");
        $titleP.html($title+'<span>更多</span>');
        $bigDiv.append($titleP);
        $bigImg = $("<img class='bigImg'>");
        $bigImg.attr("src",$bigUrl);
        $bigDiv.append($bigImg);
        $hengtu.append($bigDiv);
        var $dan = $("<div class='dan3'></div>")
        $bigDiv.before($dan);

        var $bigDiv2 = $("<ul class='bigDiv2'></ul>");
        $bigDiv.append($bigDiv2)
        var $goods = $three5.category_detail.goods;
        for(var $good of $goods){
          // console.log($good);
          var $goodUrl = $good.img;
          var $keywords = $good.name;
          var $pm_desc = $good.pm_desc;
          var $specifics = $good.specifics;
          var $oldPrice = $good.d_price;
          var $newPrice = $good.partner_price;

          var $goodImg = $("<img>");
          $goodImg.attr("src",$goodUrl );
          var $sanLi = $("<li></li>");
          $bigDiv2.append($sanLi)
          $sanLi.append($goodImg);
          var $keyP = $("<p class='keyP'></p>");
          $keyP.text($keywords);
          $sanLi.append($keyP);
            var $val = $("<p class='xuan'></p>");
          if($good.org_source_value=="1"){
            $val.text("精选");
            $sanLi.append($val);
            $val.css("color","red");
              // border: 1px solid red;
              $val.css("border","1px solid red")

          }else{
            $val.text("1");
              $sanLi.append($val);
              $val.css("color","#fff");
              $val.css("border","1px solid #fff")

          }
          var $jing = $("<span class='jing'></span>");
          $jing.text($pm_desc);
          $sanLi.append($jing);
          var $specifics1 = $("<p class='specifics'></p>")
          $specifics1.text($specifics);
          $sanLi.append($specifics1);
          var $oldSp =$("<span class='old'></span>");
          var $newSp = $("<span class='news'></span>");

          if(isNaN($oldPrice)){
            // $oldPrice="";
            $oldSp.text("");
          }else{
            $oldSp.text("￥"+$oldPrice);
          }


            $newSp.text("￥"+$newPrice);
              $sanLi.append($newSp);
            $sanLi.append($oldSp);


          var $jia = $("<span class='jia'></span>")
          $jia.text("+");
          $sanLi.append($jia);


        }

      }

    })
  }

  return{
    jieXiHome:jieXiHome
  }
})
